package com.ocom.oauth;

import cn.hutool.core.util.HexUtil;
import cn.hutool.crypto.SecureUtil;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.jwt.Jwt;
import org.springframework.security.jwt.JwtHelper;

import java.nio.charset.StandardCharsets;

/**
 * auth主启动类
 */
@SpringBootTest
public class OauthApplicationDemo {

  String token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9" +
      ".eyJ3eEFkbWluIjpbXSwicm9sZSI6NDEsIm9yZ1JvbGVJZCI6NDUsInVzZXJfbmFtZSI6Inlhbmd6bCIsImRlcHRJZCI6IjIyMSIsImF1dGhvcml0aWVzIjpbIlJPTEVfQVBQIiwiUk9MRV9XRUIiLCJST0xFX1dYIl0sImNsaWVudF9pZCI6ImNsaWVudF85IiwibWVyY2hJZCI6MjIxLCJhcmVhSWQiOjAsInJlZ2lvbklkIjowLCJwZXJtaXNzaW9ucyI6WyJ1c2VyOmZvcm06a2YmVVZkcUd5JkxLIiwic3lzOnVzZXI6YWRtaW4iXSwic2NvcGUiOlsiYWxsIl0sImZyb20iOiI4NzMzNDY2Mjc1NTI1NDQwODA4NzM0ODM2MTEyMDgiLCJpZCI6MTAyMiwiY29tSWQiOjY5MywiZXhwIjoxNzIwNjYyNjAxLCJqdGkiOiJmMjZlZTg1MS1kNDA3LTQxNTQtYmQwMS1kNzZmNDY0NDgyY2YifQ"+
      ".feWkOxzcch6xxwJaHOdN82iGSoaSvjHrLXnvjcXbzN9CkNgMSUBHowNexs0abfjaz-RGOCC3l1dahNe9YG3lVSr6UP5_uWPEpFxYhUbfq26UZ7GZBqbVILDDp6ZtfLLQ2ewcsuZnnLKa0j70wuhJc2vVU8IyX9TxFbRJwCXZzfTwgzINr9HrzV4dgyv_gIDsgNaNGXhDUnKpNjgrgFxK116M-HK9c3bMM4MVeGxOalibmwX4tdiASOH4xVqmkaz3GUl2iqZ_awZ0RfCvQSi-IStc_1k4pZx6neIJ1Fq2urbJYLARYeF0bVNSIBi7PoF1gsXBwJ5hQDDt0fDmKFdlzg";

  @Test
  public void contentLoads() {
    Jwt jwt = JwtHelper.decode(token);
    System.out.println(jwt.getClaims());
  }

  @Test
  public void login(){
    //下载hutool依赖
    String key = "tbk0Xa67cEePvv14g5Pf1MPzIceQMN14"; // 密钥（8 字节）
    String username = "admin";
    String password = "admin123";
    username = SecureUtil.des(key.getBytes(StandardCharsets.UTF_8)).encryptBase64(username);
    password = SecureUtil.des(key.getBytes(StandardCharsets.UTF_8)).encryptBase64(password);
    System.out.println(HexUtil.encodeHex(username.getBytes(StandardCharsets.UTF_8)));
    System.out.println(HexUtil.encodeHex(password.getBytes(StandardCharsets.UTF_8)));
  }
}
